import http from '@/utils/request'

/**
 * 获取角色列表(带分页的)
 * @param {*} page 页码
 * @param {*} pagesize 每页多少条
 */
export const reqGetRoleList = (page, pagesize = 5) => {
  return http({
    method: 'get',
    url: '/sys/role',
    // get delete
    params: {
      page,
      pagesize
    }
  })
}

/**
 * 根据id删除角色
 * @param {*} id 角色id
 */
export const reqDelRole = (id) => {
  return http({
    method: 'delete',
    url: '/sys/role/' + id
  })
}

/**
 * 新增角色
 * @param {*} form { name, description }
 */
export const reqAddRole = (form) => {
  return http({
    method: 'post',
    url: '/sys/role',
    data: form
  })
}

/**
 * 基于id获取角色详情
 * @param {*} id 角色id
 */
export const reqGetRoleDetail = (id) => {
  return http({
    method: 'get',
    url: `/sys/role/${id}`
  })
}

/**
 * 根据id更新角色
 * @param {*} form 要有id属性
 */
export const reqUpdateRole = (form) => {
  return http({
    method: 'put',
    url: `/sys/role/${form.id}`,
    data: form
  })
}

/**
 * 给用户分配角色
 * @param {*} id 用户id
 * @param {*} roleIds 角色id组成的数组 ['asdsd', 'asdasd' ]
 */
export const reqAssignRoles = (id, roleIds) => {
  return http({
    method: 'put',
    url: '/sys/user/assignRoles',
    data: {
      id: id,
      roleIds
    }
  })
}

export function reqAssignPerm(id, permIds) {
  return http({
    method: 'put',
    url: '/sys/role/assignPrem',
    data: {
      id,
      permIds
    }
  })
}
